/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpe.yana.testp1;

import java.util.Stack;

/**
 *
 * @author yana
 */
public class Tower {

    private Stack<Disk> disks = new Stack<Disk>();

    public Disk push(Disk disk) {
        if (!disks.isEmpty() && disks.peek().equals(disk)) {
            throw new IllegalArgumentException("Can't add disk " + disk
                    + " to tower " + this);
        }
        
        return disks.push(disk);
    }

    public Disk pop() {
        return disks.pop();
    }

    @Override
    public String toString() {
        return "Tower{" + disks + '}';
    }
}
